#!/usr/bin/env python
#coding=utf-8

import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest

def sendMessage(phone,msgJson,template):
    accessKeyId = 'LTAI5tPhrLG3U8hwm8xgyCpF'
    accessSecret = 'iD4aJEWlha7Ew4cTmlseYofwp7wtKl'

    client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https') # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', 'cn-hangzhou')
    request.add_query_param('PhoneNumbers', f"{phone}")
    request.add_query_param('SignName', '含光AI心理平台')
    request.add_query_param('TemplateCode', f'{template}')
    request.add_query_param('TemplateParam', f"{msgJson}")

    response = client.do_action(request)
    print(json.loads(str(response,encoding="utf-8")))
    # python2:  print(response)
    return json.loads(str(response,encoding="utf-8"))

# sendMessage("18155511215",{"code":"1234"},"SMS_480170071")
# sendMessage("18155511215",{"user_nick":"小王","date":"2025-03-15","keywords":"自杀、不想活了、被同学嘲笑"},"SMS_480260073")